package com.cevent.community.app.business.controller.admin;

import com.cevent.community.app.common.dto.MemberDto;
import com.cevent.community.app.common.dto.PageDto;
import com.cevent.community.app.common.dto.ResponseDataDto;
import com.cevent.community.app.common.exception.ValidatorException;
import com.cevent.community.app.common.service.MemberService;
import com.cevent.community.app.common.utils.ValidatorUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * @author cevent
 * @description freemarker：会员管理表接口层
 * @date 2021/9/13 18:04
 */
@RestController
@RequestMapping("/member")
public class MemberController {
private static final Logger LOG = LoggerFactory.getLogger(MemberController.class);
    //AOP日志环绕
    public static final String BUSINESS_NAME="业务模块【会员管理表】";
    @Resource
    private MemberService memberService;

    //1.dto-member获取
    @RequestMapping("/dtoList")
    public List<MemberDto> getDtoList() {
        return memberService.memberDtoList();
    }


    /*2.前端分页设置，后端pageInfo处理
     */
    @PostMapping("/pageList")
    public ResponseDataDto list(@RequestBody PageDto pageDto) {
        LOG.info("查看controller的pageDto：{}", pageDto);
        ResponseDataDto responseData = new ResponseDataDto();
        memberService.getMemberPageDtoList(pageDto);
        responseData.setResponseData(pageDto);
        return responseData;
    }

    //3.新增，流方式传参，加入@RequestBody
    @PostMapping("/save")
    public ResponseDataDto save(@RequestBody MemberDto memberDto) {
        LOG.info("传入的member DTO：{}", memberDto);

        ValidatorUtil.requiredLength(memberDto.getLoginName(), "登录名", 3, 50);
        ValidatorUtil.requiredEmpty(memberDto.getMobile(), "手机号");
        ValidatorUtil.requiredLength(memberDto.getMobile(), "手机号", 11, 15);
        ValidatorUtil.requiredLength(memberDto.getPassword(), "密码", 3, 255);
        /*ValidatorUtil.requiredLength(memberDto.getName(), "姓名", 6, 255);
        ValidatorUtil.requiredLength(memberDto.getNickName(), "昵称", 3, 255);
        ValidatorUtil.requiredLength(memberDto.getIcon(), "头像", 3, 500);
        ValidatorUtil.requiredLength(memberDto.getWechatCode(), "微信二维码", 3, 500);
        ValidatorUtil.requiredLength(memberDto.getEmail(), "邮箱", 3, 255);
        ValidatorUtil.requiredLength(memberDto.getIdentityNum(), "身份证号", 3, 255);
        ValidatorUtil.requiredLength(memberDto.getProvince(), "省", 3, 50);
        ValidatorUtil.requiredLength(memberDto.getCity(), "市", 3, 50);
        ValidatorUtil.requiredLength(memberDto.getDistrict(), "区", 3, 50);
        ValidatorUtil.requiredLength(memberDto.getBankNum(), "银行卡号", 3, 50);
        ValidatorUtil.requiredLength(memberDto.getBankCard(), "银行卡", 3, 500);
        ValidatorUtil.requiredLength(memberDto.getRegisterId(), "注册IP", 3, 50);
        ValidatorUtil.requiredLength(memberDto.getMotto(), "座右铭", 3, 255);*/
        ResponseDataDto responseData = new ResponseDataDto();
        memberService.save(memberDto);
        responseData.setResponseData(memberDto);
        return responseData;
    }

    /**
     * 指定请求的格式为Delete
     * 4.删除模块，如果为多个参数，就定义多个/{param}/{param}
     */
    @DeleteMapping("/del/{uniId}")
    public ResponseDataDto del(@PathVariable String uniId) {
        LOG.info("传入的member uniId：{}", uniId);
        ResponseDataDto responseData = new ResponseDataDto();
        memberService.delete(uniId);
        return responseData;
    }
}
